package com.cencat.user.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.cencat.common.entity.BaseEntity;
import com.cencat.common.enums.GrantType;
import com.cencat.common.enums.DataScope;
import com.cencat.common.enums.DataStatus;
import lombok.Data;
import lombok.EqualsAndHashCode;

import jakarta.persistence.*;
import java.time.LocalDateTime;

/**
 * 角色权限关联实体类
 * 
 * @author cencat
 * @since 2024-01-01
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "sys_role_permission")
public class RolePermission extends BaseEntity {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(type = IdType.AUTO)
    @Column(name = "id")
    private Long id;

    /**
     * 角色ID
     */
    @Column(name = "role_id", nullable = false)
    private Long roleId;

    /**
     * 权限ID
     */
    @Column(name = "permission_id", nullable = false)
    private Long permissionId;

    /**
     * 授权类型（GRANT-授权，DENY-拒绝）
     */
    @Column(name = "grant_type", nullable = false)
    @Enumerated(EnumType.STRING)
    private GrantType grantType;

    /**
     * 数据权限范围
     */
    @Column(name = "data_scope")
    @Enumerated(EnumType.STRING)
    private DataScope dataScope;

    /**
     * 自定义数据权限SQL条件
     */
    @Column(name = "data_condition", length = 1000)
    private String dataCondition;

    /**
     * 生效时间
     */
    @Column(name = "effective_time")
    private LocalDateTime effectiveTime;

    /**
     * 过期时间
     */
    @Column(name = "expiry_time")
    private LocalDateTime expiryTime;

    /**
     * 状态（ACTIVE-启用，INACTIVE-禁用）
     */
    @Column(name = "status", nullable = false)
    @Enumerated(EnumType.STRING)
    private DataStatus status;

    /**
     * 优先级（数值越大优先级越高）
     */
    @Column(name = "priority", nullable = false)
    private Integer priority;

    /**
     * 授权人ID
     */
    @Column(name = "grant_by")
    private Long grantBy;

    /**
     * 授权时间
     */
    @Column(name = "grant_time")
    private LocalDateTime grantTime;

    /**
     * 备注
     */
    @Column(name = "remark", length = 500)
    private String remark;
}